package controller;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import dao.UserDAO;
@Controller
public class KiemTraTenDangNhapController {
	@RequestMapping (value = "KiemTraTenDangNhap.do", method = RequestMethod.GET)
	public @ResponseBody String show(
			@RequestParam(value = "username", required = false) String tenDangNhap) throws IOException
	{
	
		UserDAO khDAO = new UserDAO();
	
		
		boolean isExistUser = khDAO.kiemTraDaTonTaiTenDangNhap(tenDangNhap);

		if(isExistUser){			
				return "success";
			}
		else{
				return "fail";
			}
		
	}
	@RequestMapping (value = "KiemTraTenDangNhapDaTonTai.do", method = RequestMethod.GET)
	public @ResponseBody String show2(
			@RequestParam(value = "username", required = false) String tenDangNhap) throws IOException
	{
	
		UserDAO khDAO = new UserDAO();
	
		
		boolean isExistUser = khDAO.kiemTraDaTonTaiTenDangNhap(tenDangNhap);

		if(isExistUser){			
				return "fail";
			}
		else{
				return "success";
			}
		
	}
	@RequestMapping (value = "KiemTraEmail.do", method = RequestMethod.GET)
	public @ResponseBody String showKiemTraEmail(
			@RequestParam(value = "email", required = false) String email) throws IOException
	{
	
		UserDAO khDAO = new UserDAO();
		boolean isExist = khDAO.kiemTraDaTonTaiEmail(email);
		
		
			if(isExist){			
				return "exist";
			}
			else{
				return "noexist";
			}
	}
	
	
	
}
